import { Storage } from "./storage";
import { authApi } from "../api";

const SESSION_KEY = "session_key";

export class Session {
  static set(value) {
    Storage.set(SESSION_KEY, value);
  }
  static exist() {
    return !!Storage.get();
  }
  static get() {
    return Storage.get(SESSION_KEY);
  }
  static remove() {
    Storage.remove(SESSION_KEY);
  }
  static async refreshImmediate() {
    console.log("正在刷新")
    const loginRes = await uni.login();
    const { code, data } = await authApi.wxLogin({code: loginRes.code});
    if (code !== 1) return;
    console.log("新的session:");
    console.log(data.session_key);
    Session.remove();
    Session.set(data.session_key);
  }
}
